home *** CD-ROM | disk | FTP | other *** search
Text File | 1989-08-14 | 59.6 KB | 2,372 lines |
- Article 12 of comp.sources.games:
- Path: tut!osu-cis!cbosgd!ihnp4!homxb!whuts!mtune!rutgers!mit-eddie!uw-beaver!tektronix!tekgen!tekred!games-request
- From: games-request@tekred.TEK.COM
- Newsgroups: comp.sources.games
- Subject: v02i055: advsys - adventure writing system, Part01/03
- Message-ID: <1731@tekred.TEK.COM>
- Date: 23 Oct 87 23:25:46 GMT
- Sender: billr@tekred.TEK.COM
- Lines: 2357
- Approved: billr@tekred.TEK.COM
-
- Submitted by: Marc Russell Pawliger <mp1w+@andrew.cmu.edu>
- Comp.sources.games: Volume 2, Issue 55
- Archive-name: advsys/Part01
-
- [Compiles and runs the sample progrom on our 4.3bsd Vax;
- beyond that no guarantees. Also, to forestall the questions
- sure to be asked, the submitter did not have the Mac
- dependent file. -br]
-
- #! /bin/sh
- # This is a shell archive. Remove anything before this line, then unpack
- # it by saving it into a file and typing "sh file". To overwrite existing
- # files, type "sh file -c". You can also feed this as standard input via
- # unshar, or by typing "sh <file", e.g.. If this archive is complete, you
- # will see the following message at the end:
- # "End of archive 1 (of 3)."
- # Contents: README MANIFEST advcom.c advint.h advscn.c advsys.doc
- # Wrapped by billr@tekred on Fri Oct 9 16:25:06 1987
- PATH=/bin:/usr/bin:/usr/ucb ; export PATH
- if test -f README -a "${1}" != "-c" ; then
- echo shar: Will not over-write existing file \"README\"
- else
- echo shar: Extracting \"README\" \(1098 characters\)
- sed "s/^X//" >README <<'END_OF_README'
- X From the begining of the advsys.doc file:
- X
- X ADVSYS - An Adventure Writing System
- X
- X Version 1.2
- X
- X by David Betz
- X 114 Davenport Avenue
- X Manchester, NH 03103
- X (603) 625-4691 (home)
- X
- X July 14, 1986
- X
- X Copyright (c) 1986, by David Betz
- X All Rights Reserved
- XPermission is hereby granted for unrestricted non-commercial use
- X
- XADVSYS is a special purpose programming language that was
- Xspecifically designed to be used to write computer text
- Xadventure games. It includes a facility for defining the kinds
- Xof objects that are common in adventures. Some objects
- Xrepresent locations on the game map, some objects represent
- Xthings that the player can find while exploring the adventure
- Xworld, and some objects represent other characters that the
- Xadventurer can encounter during his or her journeys. The
- Xadventure language also provides a facility to define actions.
- XActions are short sections of code that determine what happens
- Xin response to a command from the player. These two concepts,
- X"objects" and "actions" form the basis for the adventure
- Xlanguage.
- END_OF_README
- if test 1098 -ne `wc -c <README`; then
- echo shar: \"README\" unpacked with wrong size!
- fi
- # end of overwriting check
- fi
- if test -f MANIFEST -a "${1}" != "-c" ; then
- echo shar: Will not over-write existing file \"MANIFEST\"
- else
- echo shar: Extracting \"MANIFEST\" \(894 characters\)
- sed "s/^X//" >MANIFEST <<'END_OF_MANIFEST'
- X File Name Archive # Description
- X-----------------------------------------------------------
- X MANIFEST 1 This shipping list
- X Makefile 3
- X README 1
- X README2 3
- X advavl.c 3
- X advavl.h 3
- X advcom.c 1
- X advcom.h 3
- X advdbs.c 2
- X advdbs.h 3
- X advexe.c 3
- X advexp.c 2
- X advfcn.c 2
- X advfio.c 3
- X advint.c 3
- X advint.h 1
- X advjunk.c 3
- X advmsg.c 3
- X advprs.c 3
- X advscn.c 1
- X advsys.doc 1
- X advtrm.c 3
- X newadv.pch 3
- X objects.adi 2
- X osample.adv 2
- X readme.1st 3
- END_OF_MANIFEST
- if test 894 -ne `wc -c <MANIFEST`; then
- echo shar: \"MANIFEST\" unpacked with wrong size!
- fi
- # end of overwriting check
- fi
- if test -f advcom.c -a "${1}" != "-c" ; then
- echo shar: Will not over-write existing file \"advcom.c\"
- else
- echo shar: Extracting \"advcom.c\" \(14821 characters\)
- sed "s/^X//" >advcom.c <<'END_OF_advcom.c'
- X
- X/* advcom.c - a compiler for adventure games */
- X/*
- X Copyright (c) 1986, by David Michael Betz
- X All rights reserved
- X*/
- X
- X#include "advcom.h"
- X#include "advavl.h"
- X#include "advdbs.h"
- X
- X/* symbol tables */
- XSYMBOL *symbols;
- XARGUMENT *arguments;
- XARGUMENT *temporaries;
- X
- X/* adventure id information */
- Xchar aname[19];
- Xint aversion;
- X
- X/* word table */
- Xint wtable[WMAX+1],wcnt;
- X
- X/* object table */
- Xint otable[OMAX+1],ocnt;
- X
- X/* action table */
- Xint atable[AMAX+1],acnt;
- X
- X/* constant, variable and property symbol counts */
- Xint ccnt,vcnt,pcnt;
- X
- X/* data and code space */
- Xchar *data,*code;
- Xint dptr,cptr;
- X
- X/* buffer for building an object */
- Xint objbuf[OSIZE];
- Xint nprops;
- X
- X/* global variables */
- Xchar ifile[FMAX]; /* input file name */
- Xchar ofile[FMAX]; /* output file name */
- XFILE *ifp; /* input file pointer */
- Xunsigned int msgoff; /* message section offset */
- XTREE *words; /* word tree */
- Xint curwrd; /* current word number */
- Xint curobj; /* current object */
- Xint curact; /* current action */
- Xint def_flag; /* default action flag value */
- Xint def_mask; /* default action mask value */
- X
- X/* header information variables */
- Xint h_init; /* initialization code */
- Xint h_update; /* update code */
- Xint h_before; /* before handler code */
- Xint h_after; /* after handler code */
- Xint h_error; /* error handling code */
- X
- X/* external routines */
- Xextern char *malloc();
- Xextern char *calloc();
- Xextern TREE *tnew();
- X
- X/* external variables */
- Xextern int errcount; /* error count */
- Xextern int t_value; /* token value */
- Xextern char t_token[]; /* token string */
- Xextern char *t_names[]; /* token names */
- Xextern long ad_foff; /* data file offset */
- X
- X/* forward declarations */
- XSYMBOL *sfind();
- XSYMBOL *senter();
- Xchar *save();
- X
- X/* main - the main routine */
- Xmain(argc,argv)
- X int argc; char *argv[];
- X{
- X int tkn,obj,i;
- X
- X /* initialize */
- X#ifdef MAC
- X macinit(ifile,ofile);
- X#else
- X printf("ADVCOM v1.2 - Copyright (c) 1986, by David Betz\n");
- X#endif
- X wcnt = ocnt = acnt = ccnt = vcnt = pcnt = msgoff = 0;
- X symbols = NULL; arguments = temporaries = NULL;
- X h_init = h_update = h_before = h_after = h_error = NIL;
- X def_flag = def_mask = 0;
- X aname[0] = 0;
- X sinit();
- X
- X /* setup the code and data space */
- X if ((data = calloc(1,DMAX)) == 0)
- X fail("insufficient memory");
- X if ((code = calloc(1,CMAX)) == 0)
- X fail("insufficient memory");
- X dptr = cptr = 1; /* make sure nothing has a zero offset */
- X
- X /* get the file name */
- X#ifndef MAC
- X if (argc < 2)
- X fail("usage: advcom <file> [ <ofile> ]");
- X strcpy(ifile,argv[1]); strcat(ifile,".adv");
- X strcpy(ofile,(argc < 3 ? argv[1] : argv[2])); strcat(ofile,".dat");
- X#endif
- X
- X /* open the input file */
- X if ((ifp = fopen(ifile,"r")) == NULL)
- X fail("can't open input file");
- X
- X /* create and initialize the output file */
- X ad_create(ofile);
- X for (i = 0; i++ < 512; ad_putc('\0'))
- X ;
- X
- X /* create the word tree */
- X words = tnew();
- X
- X /* enter builtin constants */
- X center("t",-1);
- X center("nil",0);
- X
- X /* enter the builtin variables */
- X venter("$actor");
- X venter("$action");
- X venter("$dobject");
- X venter("$ndobjects");
- X venter("$iobject");
- X venter("$ocount");
- X
- X /* enter the preposition "to" */
- X add_word("to",WT_PREPOSITION);
- X
- X /* process statements until end of file */
- X while ((tkn = token()) == T_OPEN) {
- X frequire(T_IDENTIFIER);
- X
- X /* identification statement */
- X if (match("adventure"))
- X do_adventure();
- X
- X /* vocabulary statements */
- X else if (match("adjective"))
- X do_word(WT_ADJECTIVE);
- X else if (match("preposition"))
- X do_word(WT_PREPOSITION);
- X else if (match("conjunction"))
- X do_word(WT_CONJUNCTION);
- X else if (match("article"))
- X do_word(WT_ARTICLE);
- X else if (match("synonym"))
- X do_synonym();
- X
- X /* constant, variable, function and default definition statements */
- X else if (match("define"))
- X do_define();
- X else if (match("variable"))
- X do_variable();
- X else if (match("default"))
- X do_default();
- X
- X /* property definition statement */
- X else if (match("property"))
- X do_defproperty();
- X
- X /* handle the init, before and after code statements */
- X else if (match("init"))
- X h_init = do_code(t_token);
- X else if (match("update"))
- X h_update = do_code(t_token);
- X else if (match("before"))
- X h_before = do_code(t_token);
- X else if (match("after"))
- X h_after = do_code(t_token);
- X else if (match("error"))
- X h_error = do_code(t_token);
- X
- X /* action definition statement */
- X else if (match("action"))
- X do_action();
- X
- X /* object definition statements */
- X else if (match("object"))
- X do_object(t_token,NIL);
- X
- X /* object instance definition statements */
- X else if (obj = ofind(t_token))
- X do_object(t_token,obj);
- X
- X /* error, unknown statement */
- X else
- X error("Unknown statement type");
- X }
- X require(tkn,T_EOF);
- X
- X /* close the input file */
- X fclose(ifp);
- X
- X /* output the data structures */
- X output();
- X
- X /* close the output file */
- X ad_close();
- X}
- X
- X/* getvalue - get a value */
- Xint getvalue()
- X{
- X SYMBOL *sym;
- X
- X switch (token()) {
- X case T_IDENTIFIER: if (sym = sfind(t_token))
- X return (sym->s_value);
- X return (oenter(t_token));
- X case T_NUMBER: return (t_value);
- X case T_STRING: return (t_value);
- X default: error("Expecting identifier, number or string");
- X return (0);
- X }
- X}
- X
- X/* dalloc - allocate data space */
- Xint dalloc(size)
- X int size;
- X{
- X if ((dptr += size) > DMAX)
- X fail("out of data space");
- X return (dptr - size);
- X}
- X
- X/* add_word - add a word to the dictionary */
- Xint add_word(str,type)
- X char *str; int type;
- X{
- X if ((curwrd = tfind(words,str)) == NIL) {
- X if (wcnt < WMAX) {
- X curwrd = ++wcnt;
- X wtable[curwrd] = type;
- X tenter(words,str);
- X }
- X else {
- X error("too many words");
- X curwrd = 0;
- X }
- X }
- X else if (wtable[curwrd] == WT_UNKNOWN)
- X wtable[curwrd] = type;
- X else if (type != WT_UNKNOWN && type != wtable[curwrd])
- X error("Ambiguous word type");
- X return (curwrd);
- X}
- X
- X/* add_synonym - add a synonym to a word */
- Xint add_synonym(str,wrd)
- X char *str; int wrd;
- X{
- X curwrd = wrd;
- X return (tenter(words,str));
- X}
- X
- X/* getword - get a word from an object field */
- Xint getword(off)
- X int off;
- X{
- X return ((data[off] & 0xFF) | (data[off+1] << 8));
- X}
- X
- X/* putword - put a word into an object field */
- Xputword(off,dat)
- X int off,dat;
- X{
- X data[off] = dat;
- X data[off+1] = dat >> 8;
- X}
- X
- X/* getbyte - get a byte from an object field */
- Xint getbyte(off)
- X int off;
- X{
- X return (data[off]);
- X}
- X
- X/* putbyte - put a byte into an object field */
- Xputbyte(off,dat)
- X int off,dat;
- X{
- X data[off] = dat;
- X}
- X
- X/* output - output the binary data structures */
- Xoutput()
- X{
- X int woff,wsize; /* word table offset and size */
- X int ooff,osize; /* object table offset and size */
- X int aoff,asize; /* action table offset and size */
- X int toff,tsize; /* word type table offset and size */
- X int voff,vsize; /* variable table offset and size */
- X int soff,ssize; /* save area offset and size */
- X int dsize; /* data size without dictionary */
- X int dbase,cbase,size,mblk,dblk,i;
- X
- X /* make sure the adventure id information is present */
- X if (aname[0] == 0) {
- X xerror("no adventure identification information");
- X strcpy(aname,"ADVENTURE");
- X aversion = 0;
- X }
- X
- X /* pad the remainder of this message block */
- X while (msgoff & 0x007F)
- X { ad_putc('\0'); ad_putc('\0'); ad_putc('\0'); ad_putc('\0'); msgoff++; }
- X
- X /* save the size of the data area before the dictionary */
- X dsize = dptr;
- X
- X /* insert the vocabulary into the data array */
- X woutput(words->tr_root);
- X
- X /* compute table offsets */
- X woff = 0; wsize = tentries(words) * 2 + 2;
- X toff = woff + wsize; tsize = wcnt;
- X ooff = toff + tsize; osize = ocnt * 2 + 2;
- X aoff = ooff + osize; asize = acnt * 2 + 2;
- X voff = aoff + asize; vsize = vcnt * 2 + 2;
- X dbase = voff + vsize;
- X cbase = dbase + dptr;
- X
- X /* compute the resident structure size */
- X size = wsize+tsize+osize+asize+vsize+dptr+cptr;
- X
- X /* set the save area parameters */
- X soff = voff; ssize = vsize + dsize;
- X
- X /* compute the first block for message text */
- X mblk = 1;
- X dblk = (int)(ad_foff >> 9);
- X
- X /* output the word table */
- X word_out(tentries(words));
- X wtoutput(words->tr_root);
- X
- X /* output the word type table */
- X for (i = 1; i <= wcnt; i++)
- X byte_out(wtable[i]);
- X
- X /* output the object table */
- X word_out(ocnt);
- X for (i = 1; i <= ocnt; i++) {
- X if (otable[i] == NIL)
- X undef_object(i);
- X word_out(otable[i]);
- X }
- X
- X /* output the action table */
- X word_out(acnt);
- X for (i = 1; i <= acnt; i++)
- X word_out(atable[i]);
- X
- X /* beginning of saveable data */
- X
- X /* output the variable table */
- X word_out(vcnt);
- X for (i = 1; i <= vcnt; i++)
- X word_out(NIL);
- X
- X /* output the data space */
- X for (i = 0; i < dptr; )
- X byte_out(data[i++]);
- X
- X /* end of saveable data */
- X
- X /* output the code space */
- X for (i = 0; i < cptr; )
- X byte_out(code[i++]);
- X
- X /* output the file header */
- X ad_seek(0L);
- X word_out(size); /* resident structure size */
- X str_out("ADVSYS",6);/* magic information */
- X word_out(VERSION); /* data structure version number */
- X str_out(aname,18); /* adventure name */
- X word_out(aversion); /* adventure version number */
- X word_out(woff); /* word table offset */
- X word_out(toff); /* word type table offset */
- X word_out(ooff); /* object table offset */
- X word_out(aoff); /* action table offset */
- X word_out(voff); /* variable table offset */
- X word_out(dbase); /* base of data */
- X word_out(cbase); /* base of code */
- X word_out(dblk); /* first data block */
- X word_out(mblk); /* first message text block */
- X word_out(h_init); /* initialization code */
- X word_out(h_update); /* update code */
- X word_out(h_before); /* before handler code */
- X word_out(h_after); /* after handler code */
- X word_out(h_error); /* error handling code */
- X word_out(soff); /* save area offset */
- X word_out(ssize); /* save area size */
- X
- X /* show statistics */
- X printf("[ words: %d ]\n",tentries(words));
- X printf("[ word types: %d ]\n",wcnt);
- X printf("[ objects: %d ]\n",ocnt);
- X printf("[ actions: %d ]\n",acnt);
- X printf("[ variables: %d ]\n",vcnt);
- X printf("[ data: %d ]\n",dsize);
- X printf("[ code: %d ]\n",cptr);
- X printf("[ dictionary: %d ]\n",dptr-dsize);
- X printf("[ text: %ld ]\n",(long) msgoff * 4L);
- X printf("[ save area: %d ]\n",ssize);
- X printf("[ errors: %d ]\n",errcount);
- X#ifdef MAC
- X macpause();
- X#endif
- X}
- X
- X/* woutput - output the word data */
- Xwoutput(node)
- X TNODE *node;
- X{
- X int wnum,wrd;
- X
- X if (node) {
- X woutput(LLINK(node));
- X wnum = WORD(node);
- X wrd = WORD(node) = dalloc(strlen(KEY(node))+3);
- X putword(wrd,wnum);
- X strcpy(data+wrd+2,KEY(node));
- X if (wtable[wnum] == WT_UNKNOWN)
- X printf("Type of word %s is unknown\n",KEY(node));
- X woutput(RLINK(node));
- X }
- X}
- X
- X/* wtoutput - output the word table */
- Xwtoutput(node)
- X TNODE *node;
- X{
- X if (node) {
- X wtoutput(LLINK(node));
- X word_out(WORD(node));
- X wtoutput(RLINK(node));
- X }
- X}
- X
- X/* undef_object - complain about an undefined object */
- Xundef_object(n)
- X int n;
- X{
- X char msg[100];
- X SYMBOL *sym;
- X
- X for (sym = symbols; sym != NULL; sym = sym->s_next)
- X if (sym->s_type == ST_OBJECT && n == sym->s_value) {
- X sprintf(msg,"Object %s is undefined",sym->s_name);
- X xerror(msg);
- X break;
- X }
- X}
- X
- X/* str_out - output a string */
- Xstr_out(str,len)
- X char *str; int len;
- X{
- X while (len--)
- X byte_out(*str++);
- X}
- X
- X/* word_out - output a word */
- Xword_out(dat)
- X int dat;
- X{
- X byte_out(dat);
- X byte_out(dat >> 8);
- X}
- X
- X/* byte_out - output a byte */
- Xbyte_out(dat)
- X int dat;
- X{
- X ad_putc((~dat - 30) & 0xFF);
- X}
- X
- X/* oenter - enter an object into the symbol table */
- Xint oenter(name)
- X char *name;
- X{
- X SYMBOL *sym;
- X
- X if (sym = sfind(name)) {
- X if (sym->s_type != ST_OBJECT)
- X error("Not an object");
- X return (sym->s_value);
- X }
- X if (ocnt < OMAX) {
- X senter(name,ST_OBJECT,++ocnt);
- X otable[ocnt] = NIL;
- X }
- X else
- X error("too many objects");
- X return (ocnt);
- X}
- X
- X/* ofind - find an object in the symbol table */
- Xint ofind(name)
- X char *name;
- X{
- X SYMBOL *sym;
- X
- X if (sym = sfind(name)) {
- X if (sym->s_type != ST_OBJECT)
- X return (NIL);
- X return (sym->s_value);
- X }
- X return (NIL);
- X}
- X
- X/* aenter - enter an action into the symbol table */
- Xint aenter(name)
- X char *name;
- X{
- X SYMBOL *sym;
- X
- X if (sym = sfind(name)) {
- X if (sym->s_type != ST_ACTION)
- X error("Not an action");
- X return (sym->s_value);
- X }
- X if (acnt < AMAX) {
- X senter(name,ST_ACTION,++acnt);
- X atable[acnt] = NIL;
- X }
- X else
- X error("too many actions");
- X return (acnt);
- X}
- X
- X/* venter - enter a variable into the symbol table */
- Xint venter(name)
- X char *name;
- X{
- X SYMBOL *sym;
- X
- X if (sym = sfind(name)) {
- X if (sym->s_type != ST_VARIABLE)
- X error("Not a variable");
- X return (sym->s_value);
- X }
- X senter(name,ST_VARIABLE,++vcnt);
- X return (vcnt);
- X}
- X
- X/* penter - enter a property into the symbol table */
- Xint penter(name)
- X char *name;
- X{
- X SYMBOL *sym;
- X
- X if (sym = sfind(name)) {
- X if (sym->s_type != ST_PROPERTY)
- X error("Not a property");
- X return (sym->s_value);
- X }
- X senter(name,ST_PROPERTY,++pcnt);
- X return (pcnt);
- X}
- X
- X/* center - enter a constant into the symbol table */
- Xcenter(name,value)
- X char *name; int value;
- X{
- X if (sfind(name)) {
- X error("Already defined");
- X return;
- X }
- X senter(name,ST_CONSTANT,value);
- X}
- X
- X/* sfind - find a symbol in the symbol table */
- XSYMBOL *sfind(name)
- X char *name;
- X{
- X SYMBOL *sym;
- X
- X for (sym = symbols; sym != NULL; sym = sym->s_next)
- X if (strcmp(name,sym->s_name) == 0)
- X break;
- X return (sym);
- X}
- X
- X/* senter - enter a symbol into the symbol table */
- XSYMBOL *senter(name,type,value)
- X char *name; int type,value;
- X{
- X SYMBOL *sym;
- X
- X if ((sym = (SYMBOL *)malloc(sizeof(SYMBOL))) == NULL)
- X fail("out of memory");
- X sym->s_name = save(name);
- X sym->s_type = type;
- X sym->s_value = value;
- X sym->s_next = symbols;
- X symbols = sym;
- X return (sym);
- X}
- X
- X/* frequire - fetch a token and check it */
- Xfrequire(rtkn)
- X int rtkn;
- X{
- X require(token(),rtkn);
- X}
- X
- X/* require - check for a required token */
- Xrequire(tkn,rtkn)
- X int tkn,rtkn;
- X{
- X char msg[100];
- X if (tkn != rtkn) {
- X sprintf(msg,"Expecting %s",t_names[rtkn]);
- X error(msg);
- X }
- X}
- X
- X/* save - allocate memory for a string */
- Xchar *save(str)
- X char *str;
- X{
- X char *new;
- X
- X if ((new = malloc(strlen(str)+1)) == NULL)
- X fail("out of memory");
- X strcpy(new,str);
- X return (new);
- X}
- X
- X/* match - compare a string with the current token */
- Xint match(str)
- X char *str;
- X{
- X return (strcmp(str,t_token) == 0);
- X}
- X
- X/* fail - print an error message and exit */
- Xfail(msg)
- X char *msg;
- X{
- X printf("%s\n",msg);
- X#ifdef MAC
- X macpause();
- X#endif
- X exit();
- X}
- X
- END_OF_advcom.c
- if test 14821 -ne `wc -c <advcom.c`; then
- echo shar: \"advcom.c\" unpacked with wrong size!
- fi
- # end of overwriting check
- fi
- if test -f advint.h -a "${1}" != "-c" ; then
- echo shar: Will not over-write existing file \"advint.h\"
- else
- echo shar: Extracting \"advint.h\" \(362 characters\)
- sed "s/^X//" >advint.h <<'END_OF_advint.h'
- X
- X/* advint.h - adventure interpreter definitions */
- X/*
- X Copyright (c) 1986, by David Michael Betz
- X All rights reserved
- X*/
- X
- X#include <stdio.h>
- X#include <ctype.h>
- X
- X/* useful definitions */
- X#define TRUE 1
- X#define FALSE 0
- X#define EOS '\0'
- X
- X/* program limits */
- X#define STKSIZE 500
- X
- X/* code completion codes */
- X#define FINISH 1
- X#define CHAIN 2
- X#define ABORT 3
- END_OF_advint.h
- if test 362 -ne `wc -c <advint.h`; then
- echo shar: \"advint.h\" unpacked with wrong size!
- fi
- # end of overwriting check
- fi
- if test -f advscn.c -a "${1}" != "-c" ; then
- echo shar: Will not over-write existing file \"advscn.c\"
- else
- echo shar: Extracting \"advscn.c\" \(6037 characters\)
- sed "s/^X//" >advscn.c <<'END_OF_advscn.c'
- X
- X/* advscn.c - a lexical scanner for the adventure compiler */
- X/*
- X Copyright (c) 1986, by David Michael Betz
- X All rights reserved
- X*/
- X
- X#include "advcom.h"
- X
- X/* useful definitions */
- X#define maplower(ch) (isupper(ch) ? tolower(ch) : ch)
- X
- X/* global variables */
- Xint errcount=0; /* error count */
- Xint t_value; /* numeric value */
- Xchar t_token[TKNSIZE+1];/* token string */
- Xchar *t_names[] = {
- X 0,
- X "(",
- X ")",
- X "STRING",
- X "IDENTIFIER",
- X "NUMBER",
- X "EOF"
- X};
- X
- X/* external variables */
- Xextern FILE *ifp; /* input file pointer */
- Xextern int msgoff; /* message section offset */
- X
- X/* local variables */
- Xstatic int savetkn = 0; /* look ahead token */
- Xstatic int savech = 0; /* look ahead character */
- Xstatic char fname[200]; /* include file name */
- Xstatic char line[200]; /* current input line */
- Xstatic char *lptr; /* line pointer */
- Xstatic int lnum; /* line number */
- Xstatic int ieof; /* input end of file flag */
- Xstatic int save_lnum; /* saved lnum */
- Xstatic FILE *save_ifp; /* saved ifp */
- Xstatic int scnt; /* count of characters in string */
- X
- X/* sinit - initialize the scanner */
- Xsinit()
- X{
- X /* setup the line buffer */
- X lptr = line; *lptr = 0;
- X lnum = 0;
- X
- X /* no include file yet */
- X save_ifp = NULL;
- X
- X /* no lookahead yet */
- X savech = 0;
- X savetkn = 0;
- X
- X /* not eof yet */
- X ieof = FALSE;
- X}
- X
- X/* token - get the next token */
- Xint token()
- X{
- X int tkn;
- X
- X if (tkn = savetkn)
- X savetkn = 0;
- X else
- X tkn = rtoken();
- X return (tkn);
- X}
- X
- X/* stoken - save a token */
- Xstoken(tkn)
- X int tkn;
- X{
- X savetkn = tkn;
- X}
- X
- X/* rtoken - read the next token */
- Xint rtoken()
- X{
- X int ch;
- X
- X /* check the next character */
- X for (;;)
- X switch (ch = skipspaces()) {
- X case EOF: return (T_EOF);
- X case '(': strcpy(t_token,"("); return (T_OPEN);
- X case ')': strcpy(t_token,")"); return (T_CLOSE);
- X case '"': return (getstring());
- X case ';': while (getch() != '\n'); break;
- X default: return (getid(ch));
- X }
- X}
- X
- X/* getstring - get a string */
- Xint getstring()
- X{
- X int ch,sflag;
- X
- X t_value = msgoff;
- X sflag = FALSE;
- X scnt = 0;
- X while ((ch = getch()) != EOF && ch != '"')
- X if (isspace(ch))
- X sflag = TRUE;
- X else {
- X if (ch == '\\')
- X switch (ch = getch()) {
- X case 'n': ch = '\n'; break;
- X case 't': ch = '\t'; break;
- X }
- X if (sflag)
- X { wputc(' '); sflag = FALSE; }
- X wputc(ch);
- X }
- X if (sflag)
- X wputc(' ');
- X strdone();
- X strcpy(t_token,"{string}");
- X return (T_STRING);
- X}
- X
- X/* getid - get an identifier */
- Xint getid(ch)
- X int ch;
- X{
- X char *p;
- X
- X p = t_token; *p++ = maplower(ch);
- X while ((ch = getch()) != EOF && isidchar(ch))
- X *p++ = maplower(ch);
- X *p = EOS;
- X savech = ch;
- X return (isnumber(t_token,&t_value) ? T_NUMBER : T_IDENTIFIER);
- X}
- X
- X/* isnumber - check if this string is a number */
- Xint isnumber(str,pval)
- X char *str; int *pval;
- X{
- X int digits;
- X char *p;
- X
- X /* initialize */
- X p = str; digits = 0;
- X
- X /* check for a sign */
- X if (*p == '+' || *p == '-')
- X p++;
- X
- X /* check for a string of digits */
- X while (isdigit(*p))
- X p++, digits++;
- X
- X /* make sure there was at least one digit and this is the end */
- X if (digits == 0 || *p)
- X return (FALSE);
- X
- X /* convert the string to an integer and return successfully */
- X if (*str == '+') ++str;
- X *pval = atoi(str);
- X return (TRUE);
- X}
- X
- X/* wputc - put a character into the output file */
- Xwputc(ch)
- X int ch;
- X{
- X ad_putc(encode(ch));
- X scnt++;
- X}
- X
- X/* strdone - finish a string */
- Xstrdone()
- X{
- X wputc('\0');
- X while (scnt & 3)
- X wputc('\0');
- X msgoff += scnt >> 2;
- X}
- X
- X/* skipspaces - skip leading spaces */
- Xskipspaces()
- X{
- X int ch;
- X
- X while ((ch = getch()) && isspace(ch))
- X ;
- X return (ch);
- X}
- X
- X/* isidchar - is this an identifier character */
- Xint isidchar(ch)
- X int ch;
- X{
- X return (!isspace(ch) && ch != '(' && ch != ')' && ch != '"');
- X}
- X
- X/* getch - get the next character */
- Xint getch()
- X{
- X FILE *fp;
- X int ch;
- X
- X /* check for a lookahead character */
- X if (ch = savech)
- X savech = 0;
- X
- X /* check for a buffered character */
- X else if (ch = *lptr)
- X lptr++;
- X
- X /* check for end of file */
- X else if (ieof)
- X ch = EOF;
- X
- X /* read another line */
- X else {
- X
- X /* read the line */
- X for (lptr = line; (ch = getchr()) != EOF && (*lptr++ = ch) != '\n';)
- X ;
- X *lptr = 0;
- X lnum++;
- X
- X /* check for an included file */
- X if (line[0] == '@') {
- X
- X /* open the file */
- X strcpy(fname,&line[1]); fname[strlen(fname)-1] = 0;
- X if ((fp = fopen(fname,"r")) == NULL) {
- X printf("Can't open include file: %s\n",fname);
- X exit();
- X }
- X printf("[ including %s ]\n",fname);
- X
- X /* setup input from the file */
- X save_lnum = lnum;
- X save_ifp = ifp;
- X ifp = fp;
- X
- X /* setup for the first line */
- X lptr = line; *lptr = 0;
- X lnum = 0;
- X }
- X
- X /* otherwise this must be an input line */
- X else {
- X
- X /* terminate the line with a newline */
- X *lptr++ = '\n'; *lptr = 0;
- X
- X /* check for end of file */
- X if (ch == EOF)
- X ieof = TRUE;
- X
- X /* update the line number and setup for the new line */
- X lptr = line;
- X }
- X
- X /* get a character */
- X ch = getch();
- X }
- X
- X /* return the current character */
- X return (ch);
- X}
- X
- X/* getchr - get a character checking for end of file */
- Xint getchr()
- X{
- X int ch;
- X
- X if ((ch = getc(ifp)) == EOF || ch == '\032') {
- X if (save_ifp) {
- X printf("[ end of %s ]\n",fname);
- X fclose(ifp);
- X lnum = save_lnum;
- X ifp = save_ifp;
- X save_ifp = NULL;
- X ch = getchr();
- X }
- X else
- X ch = EOF;
- X }
- X else if (ch == '\r')
- X ch = getchr();
- X return (ch);
- X}
- X
- X/* encode - encode a single character */
- Xint encode(ch)
- X int ch;
- X{
- X return ((ch - 30) & 0xFF);
- X}
- X
- X/* error - report an error in the current line */
- Xerror(msg)
- X char *msg;
- X{
- X char *p;
- X
- X printf(">>> %s <<<\n>>> in line %d <<<\n%s",msg,lnum,line);
- X for (p = line; p < lptr; p++)
- X if (*p == '\t')
- X putchar('\t');
- X else
- X putchar(' ');
- X printf("^\n");
- X errcount++;
- X#ifdef MAC
- X macpause();
- X#endif
- X}
- X
- X/* xerror - report an error in the current line */
- Xxerror(msg)
- X char *msg;
- X{
- X printf(">>> %s <<<\n",msg);
- X errcount++;
- X}
- END_OF_advscn.c
- if test 6037 -ne `wc -c <advscn.c`; then
- echo shar: \"advscn.c\" unpacked with wrong size!
- fi
- # end of overwriting check
- fi
- if test -f advsys.doc -a "${1}" != "-c" ; then
- echo shar: Will not over-write existing file \"advsys.doc\"
- else
- echo shar: Extracting \"advsys.doc\" \(29358 characters\)
- sed "s/^X//" >advsys.doc <<'END_OF_advsys.doc'
- X
- X
- X
- X
- X
- X
- X
- X ADVSYS - An Adventure Writing System
- X
- X Version 1.2
- X
- X by David Betz
- X 114 Davenport Avenue
- X Manchester, NH 03103
- X (603) 625-4691 (home)
- X
- X July 14, 1986
- X
- X Copyright (c) 1986, by David Betz
- X All Rights Reserved
- X Permission is hereby granted for unrestricted non-commercial use
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X ADVSYS An Adventure Writing System Page 2
- X
- X
- X INTRODUCTION
- X
- X ADVSYS is a special purpose programming language that was
- X specifically designed to be used to write computer text
- X adventure games. It includes a facility for defining the kinds
- X of objects that are common in adventures. Some objects
- X represent locations on the game map, some objects represent
- X things that the player can find while exploring the adventure
- X world, and some objects represent other characters that the
- X adventurer can encounter during his or her journeys. The
- X adventure language also provides a facility to define actions.
- X Actions are short sections of code that determine what happens
- X in response to a command from the player. These two concepts,
- X "objects" and "actions" form the basis for the adventure
- X language.
- X
- X
- X ACKNOWLEDGEMENTS
- X
- X Although I have written all of the code associated with this
- X adventure writing system, I must acknowledge the assistance of
- X one individual without whom this project would probably never
- X have reached completion. That person is Gary McGath. Gary was
- X interested in writing a commercial quality adventure game and I
- X convinced him to write it using my system (which was as yet
- X almost completely unspecified) instead of using a traditional
- X programming language. The input that Gary provided during the
- X development of his game contributed significantly to the overall
- X design of the system. I would like to thank Gary for that
- X contribution.
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X ADVSYS An Adventure Writing System Page 3
- X
- X
- X USING THE SYSTEM TO WRITE AN ADVENTURE
- X
- X In order to write an adventure using this system, you need to
- X write an adventure description. This is an ordinary ASCII text
- X file containing definitions for all of the objects and actions
- X in your adventure game. This file is used as input to the
- X adventure compiler. The compiler takes the adventure
- X description and compiles it into a set of data structures.
- X
- X In order to play an adventure written using this system, you
- X need the data structure file that was produced by the compiler
- X and the adventure interpreter program. The interpreter uses the
- X information produced by the adventure compiler to allow a player
- X to play the adventure game. Notice that it is not necessary for
- X the player to have access to the original adventure description
- X file. All of the information that is necessary to play the
- X adventure game is contained within the data structure file that
- X is produced by the compiler. This file is a binary file that
- X cannot be simply "listed" to reveal the internal workings of the
- X adventure.
- X
- X The adventure compiler is called ADVCOM and the interpreter is
- X called ADVINT. These two programs in conjunction with this
- X documentation are all that is required to write and play
- X adventure games using this system.
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X ADVSYS An Adventure Writing System Page 4
- X
- X
- X RUNNING THE COMPILER
- X
- X If you have created an adventure definition file called
- X "MYADV.ADV", you can compile it with the command:
- X
- X A>advcom myadv
- X
- X Typing this command will invoke the adventure compiler and cause
- X it to compile the file named "MYADV.ADV". The ".ADV" extension
- X is added to the file name by the compiler. During the process
- X of compiling the file, many messages will be printed telling
- X about the progress of the compiler. At the end of the
- X compilation process, the compiler prints a set of statistics
- X describing the resulting data structure file. This file will be
- X called "MYADV.DAT". It contains the data structures needed by
- X the adventure interpreter to allow a player to play the
- X adventure game.
- X
- X Note: The "A>" in the line above is the MS-DOS prompt and should
- X not be typed as part of the command.
- X
- X
- X RUNNING THE INTERPRETER
- X
- X Assuming that you have a compiled adventure data file called
- X "MYADV.DAT", you can play the adventure by typing the command:
- X
- X A>advint myadv
- X
- X This command will start the adventure. There will probably be
- X some text printed at this point describing the adventure and the
- X initial situation. You will then be prompted to type a command.
- X The prompt is the colon character. The format for commands is
- X described under the section about the parser. After typing a
- X command, you will be told what happened as a result of your
- X command, your new situation will be described and you will begin
- X the loop again.
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X ADVSYS An Adventure Writing System Page 5
- X
- X
- X ADVENTURE DESCRIPTION FILE FORMAT
- X
- X All adventure description files contain a collection of
- X statements. These statements must be formed according to
- X the following rules:
- X
- X
- X The adventure definition statement:
- X
- X All adventure definitions should have an ADVENTURE
- X statement. This statement gives the name of the adventure
- X and the version number of the definition file. Each
- X adventure should have a unique name. This name is used to
- X identify "saved position" files and insure that only files
- X that correspond to the current adventure are restored. The
- X version number allows the author to have many versions of
- X the same adventure during development and guarantee that
- X "save" files from one version aren't restored into another
- X version.
- X
- X (ADVENTURE name version)
- X
- X Example:
- X
- X (ADVENTURE sample 1)
- X
- X
- X Vocabulary statements:
- X
- X These statements add words to the adventure vocabulary.
- X
- X (ADJECTIVE word*)
- X (PREPOSITION word*)
- X (CONJUNCTION word*)
- X (ARTICLE word*)
- X (SYNONYM word synonym*)
- X
- X Examples:
- X
- X (ADJECTIVE red blue)
- X (CONJUNCTION and)
- X (SYNONYM big large)
- X
- X Note:
- X
- X Words are also added to the vocabulary by the object
- X and action definitions using the NOUN, ADJECTIVE, VERB
- X and PREPOSITION statements.
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X ADVSYS An Adventure Writing System Page 6
- X
- X
- X Constant definition statement:
- X
- X (DEFINE name value)
- X
- X Examples:
- X
- X (DEFINE what "I don't understand what you're saying!\\n")
- X (DEFINE max-load 100)
- X
- X
- X Function definition statement:
- X
- X (DEFINE (function-name [arg-name]* [&aux tmp-name*]) expr*)
- X
- X Example:
- X
- X (DEFINE (factorial n)
- X (IF (< n 2)
- X 1
- X (* n (factorial (- n 1)))))
- X
- X
- X Variable definition statement:
- X
- X (VARIABLE variable-name*)
- X
- X Example:
- X
- X (VARIABLE score i j)
- X
- X
- X Property name definition statement:
- X
- X (PROPERTY property-name*)
- X
- X Example:
- X
- X (PROPERTY weight value)
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X ADVSYS An Adventure Writing System Page 7
- X
- X
- X Comments:
- X
- X Comments begin with a semi-colon and end with the end of the
- X line.
- X
- X Example:
- X
- X ; this is a comment
- X
- X
- X Include files:
- X
- X Any line that begins with a "@" causes the inclusion of
- X another file. The file name immediately follows the at-sign
- X and extends to the end of the line. Only one level of
- X include is supported.
- X
- X Example:
- X
- X @basic.adv
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X ADVSYS An Adventure Writing System Page 8
- X
- X
- X Handler definition statements:
- X
- X (INIT expr*)
- X (UPDATE expr*)
- X (BEFORE expr*)
- X (AFTER expr*)
- X (ERROR expr*)
- X
- X Example:
- X
- X (INIT
- X (print "Welcome to the sample adventure!\\n"))
- X
- X
- X Handlers:
- X
- X All activity within an adventure game is controlled by a
- X built-in handler loop. Each of the handlers in the loop
- X contains code that is provided by the adventure author. The
- X sequencing from handler to handler is provided by the
- X adventure system itself.
- X
- X The first handler that is called in an adventure game is the
- X INIT handler. It prints some sort of introductory text and
- X initializes all global variables in order to start the
- X adventure game.
- X
- X After the INIT handler has completed, the normal loop is
- X entered. It starts with the UPDATE handler. The UPDATE
- X handler prepares for the player's next turn. It should
- X describe the player's location if it has changed since the
- X last turn. After the UPDATE handler completes, the parser
- X is called. It prompts the player for a command, parses the
- X command, sets the built-in parser varaibles and exits. Then
- X the BEFORE handler is called. It is called before the
- X action associated with the command to allow the adventure
- X author to inspect the parser variables before proceeding to
- X the action itself. After the BEFORE handler completes, the
- X action itself is called (or whatever action is stored in the
- X built-in variable $ACTION when the BEFORE handler
- X completes). When the action completes, the AFTER handler is
- X called to give the author a chance to handle events that
- X happen only at the end of a successful turn. The ERROR
- X handler is called when the parser detects an error.
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X ADVSYS An Adventure Writing System Page 9
- X
- X
- X The handler loop:
- X
- X INIT
- X |
- X v
- X UPDATE<----------+
- X | |
- X v |
- X parse--->ERROR---+
- X | |
- X v |
- X BEFORE |
- X | |
- X v |
- X action |
- X | |
- X v |
- X AFTER------------+
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X ADVSYS An Adventure Writing System Page 10
- X
- X
- X The parser:
- X
- X The parser handles all commands from the player. It prompts
- X the player when it is ready for a new command. The prompt
- X is the colon character. When the player has typed a
- X command, the parser breaks the command into phrases. The
- X parser recognizes the following command forms:
- X
- X [actor,] verb
- X [actor,] verb dobjects
- X [actor,] verb dobjects preposition iobject
- X [actor,] verb iobject dobjects
- X
- X Where:
- X
- X actor ==> a noun phrase
- X verb ==> the verb phrase (1 or 2 words)
- X dobjects ==> dobject [conjunction dobject]*
- X dobject ==> a noun phrase
- X preposition ==> a preposition
- X iobject ==> a noun phrase
- X noun phrase ==> [article] [adjective]* noun
- X
- X Examples:
- X
- X Look
- X Take the red magic sword
- X Take the red sword and the blue bottle
- X Give the troll the red sword
- X Give the red sword to the troll
- X Troll, give me the sword
- X
- X Notes:
- X
- X Square brackets enclose optional phrases. An asterisk
- X indicates zero or more of the preceeding element.
- X
- X The fourth form above is treated as if the player had
- X typed:
- X
- X [actor,] verb dobject "to" iobject
- X
- X Once the parser has broken the command into phrases, it
- X assigns each noun phrase a number. It stores the number of
- X the actor noun phrase in the built-in variable $ACTOR. It
- X stores the first direct object noun phrase number in the
- X variable $DOBJECT. It stores the number of direct objects
- X in the variable $NDOBJECTS. It stores the indirect object
- X noun phrase number in the variable $IOBJECT. If any of the
- X noun phrases is missing from the command, the corresponding
- X variable is set to NIL. The parser saves the verb phrase
- X and preposition to use when determining which action to use
- X to handle the command.
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X ADVSYS An Adventure Writing System Page 11
- X
- X
- X Action definition statement:
- X
- X Actions are used to handle player commands. Each time the
- X parser finishes parsing a new command, it uses the verb
- X phrase and the preposition to locate an action to handle the
- X command. Each action specifies a kind of template that must
- X match the command in order for the action to be called. The
- X template consists of the words used in the verb phrase and
- X preposition and the existance of the actor, direct object
- X and indirect object noun phrases. Once the parser finds an
- X action that matches the command, it stores the action in the
- X built-in variable $ACTION and exits.
- X
- X (ACTION action-name astat*)
- X astat:
- X (ACTOR [flag])
- X (VERB verb*)
- X (DIRECT-OBJECT [flag])
- X (PREPOSITION word*)
- X (INDIRECT-OBJECT [flag])
- X flag:
- X REQUIRED must have the corresponding np
- X OPTIONAL may have the corresponding np
- X FORBIDDEN must not have the corresponding np
- X verb:
- X word
- X (word word)
- X
- X Example:
- X
- X (ACTION take
- X (VERB take (pick up))
- X (DIRECT-OBJECT)
- X (CODE
- X (print "You can't take the ")
- X (print-noun $dobject)
- X (print "!\\n")))
- X
- X If the ACTOR, DIRECT-OBJECT or INDIRECT-OBJECT statements
- X are left out entirely, the settings of the corresponding
- X flags are taken from the action default definitions. If
- X there is no action default definition, the value FORBIDDEN
- X is assumed. If any of these statements is present, but no
- X flag is specified, it is treated as if the flag REQUIRED was
- X specified.
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X ADVSYS An Adventure Writing System Page 12
- X
- X
- X Action default definition statement:
- X
- X This statement defines default values for the ACTOR, DIRECT-
- X OBJECT and INDIRECT-OBJECT flags.
- X
- X (DEFAULT dstat*)
- X dstat:
- X (ACTOR [flag])
- X (DIRECT-OBJECT [flag])
- X (INDIRECT-OBJECT [flag])
- X flag:
- X REQUIRED
- X OPTIONAL
- X FORBIDDEN
- X
- X Example:
- X
- X (DEFAULT
- X (ACTOR OPTIONAL))
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X ADVSYS An Adventure Writing System Page 13
- X
- X
- X Object definition statements:
- X
- X The object definition statements are used to define
- X individual objects and classes of objects. The most basic
- X way of defining an object is using the (OBJECT ...)
- X statement. This defines an object which has no parent
- X class.
- X
- X It is also possible to create a class of objects that share
- X information. A class is defined just like a normal object.
- X It is given nouns, adjectives and properties. In addition,
- X a class may have class properties. These are properties
- X that are shared amongst all instances of the class. In
- X order to create an instance of a class, the (class-name ...)
- X form is used. This creates an instance of the named class.
- X An instance will inherit all nouns and adjectives from its
- X parent class. It will also inherit all class properties
- X defined in the parent (and its parents). Any normal
- X properties defined in the parent class will be copied to the
- X new object. The copies will have the same values that the
- X parent has, but it is possible for the instance to have
- X property definitions that override these values. Instances
- X may also have additional nouns, adjectives and properties.
- X
- X (OBJECT object-name ostat*)
- X (class-name object-name ostat*)
- X ostat:
- X (NOUN word*)
- X (ADJECTIVE word*)
- X (PROPERTY [property-name value]*)
- X (CLASS-PROPERTY [property-name value]*)
- X (METHOD (selector [arg-name]* [&aux tmp-name*])
- X expr*)
- X class-name:
- X the name of a previously defined object
- X
- X Examples:
- X
- X (OBJECT sword
- X (NOUN sword weapon)
- X (CLASS-PROPERTY
- X is-weapon T)
- X (PROPERTY
- X weight 10
- X value 5
- X damage 20))
- X
- X (sword red-sword
- X (ADJECTIVE red)
- X (PROPERTY
- X damage 25))
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X ADVSYS An Adventure Writing System Page 14
- X
- X
- X Expressions:
- X
- X (+ expr expr) add
- X (- expr expr) subtract
- X (* expr expr) multiply
- X (/ expr expr) divide
- X (% expr expr) remainder
- X
- X (& expr expr) bit-wise and
- X (| expr expr) bit-wise or
- X (~ expr) bit-wise complement
- X
- X These arithmetic functions operate on integers. As it turns
- X out, every data type in the system is represented by an
- X integer, so these functions will work with any type of
- X arguments. They are probably only useful with integers,
- X however.
- X
- X (RANDOMIZE) reset the random number generator
- X (RAND expr) generate a random number
- X
- X These functions enable the generation of pseudo-random
- X numbers. The (RAND n) function takes a single argument and
- X generates a random number between zero and n-1. (RANDOMIZE)
- X resets the seed used by the random number function so that
- X each invocation of a program results in a new sequence of
- X random numbers.
- X
- X (AND expr*) logical and (short circuits)
- X (OR expr*) logical or (short circuits)
- X (NOT expr) logical not
- X
- X These functions operate on logical values. In this system,
- X any value that is not equal to NIL (or zero) is considered
- X true. NIL and zero are considered false. AND and OR
- X evaluate their arguments from left to right and stop as soon
- X as the value of the entire expression can be determined. In
- X other words, AND stops when it encounters a false value, OR
- X stops when it encounters a true value.
- X
- X (< expr expr) less than
- X (= expr expr) equal to
- X (> expr expr) greater than
- X
- X These functions compare integers. They cannot be used to
- X compare strings.
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X ADVSYS An Adventure Writing System Page 15
- X
- X
- X (GETP obj property-name) get the value of a property
- X (SETP obj property-name value) set the value of a property
- X
- X These functions manipulate object properties. They are used
- X to find the value of a property or to set the value of a
- X property. They will also find and set the values of
- X inherited properties. If GETP is used to find the value of
- X a property that doesn't exist for the specified object, NIL
- X is returned. If SETP is used to set the value of a property
- X that doesn't exist, the operation is ignored.
- X
- X (CLASS obj)
- X
- X This function returns the class of an object. If the object
- X was defined with an (OBJECT ...) statement, NIL will be
- X returned. If the object was defined with the (class-name
- X ...) statement, the class object will be returned.
- X
- X (MATCH obj noun-phrase-number)
- X
- X This function matches an object with a noun phrase. An
- X object matches a noun phrase if it includes all of the
- X adjectives specified in the noun phrase and also includes
- X the noun mentioned. Both nouns and adjectives can be
- X inherited.
- X
- X (YES-OR-NO) get a yes or no answer from the player
- X
- X This function waits for the player to type a line. If the
- X line begins with a 'Y' or a 'y', the function returns T. If
- X the line begins with anything else, the function returns
- X NIL.
- X
- X (PRINT expr) print a string
- X (PRINT-NUMBER expr) print a number
- X (PRINT-NOUN noun-phrase-number) print a noun phrase
- X (TERPRI) terminate the print line
- X
- X These functions perform various sorts of output. PRINT
- X prints strings, PRINT-NUMBER prints numbers and PRINT-NOUN
- X prints a noun phrase.
- X
- X (FINISH) exit and continue with the AFTER handler
- X (CHAIN) exit and continue with the next handler
- X (ABORT) exit and continue with the UPDATE handler
- X (RESTART) exit and restart the current game
- X (EXIT) exit to the operating system
- X
- X These functions cause the immediate termination of the
- X current handler. FINISH causes execution to proceed with
- X the AFTER handler, CHAIN causes execution to proceed with
- X the next handler in the normal sequence, ABORT causes
- X execution to proceed with the UPDATE handler (effectively
- X aborting the current turn), RESTART restores the game to its
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X ADVSYS An Adventure Writing System Page 16
- X
- X
- X original state and starts over with the INIT handler and
- X EXIT causes an immediate exit back to the operating system.
- X
- X (SAVE) save the current game position
- X (RESTORE) restore a saved game position
- X
- X These functions allow the player to save and restore
- X positions in the game. They prompt the player for a file
- X name and either read a saved game position from the file or
- X write the current game position to the file.
- X
- X (function-name expr*)
- X
- X This expression invokes a user defined function. There
- X should be one expression for each of the formal arguments of
- X the user function. The value of the expression is the value
- X of the last expression in the body of the user function or
- X the value passed to a RETURN statement within the function.
- X
- X (SEND object selector [expr]*)
- X
- X This expression sends a message to an object. The "object"
- X expression should evaluate to an object. The selector
- X should match a method selector for that object or one of its
- X super-classes. The matching method is invoked with the
- X specified expressions as arguments. Also, the implied
- X argument SELF will refer to the object receiving the
- X message.
- X
- X (SEND-SUPER selector [expr]*)
- X
- X This expression sends a message to the super-class of the
- X current object. It can only be used within a method and it
- X will cause the message to be passed up the class heirarchy
- X to the super-class of the object refered to by SELF.
- X
- X (SETQ variable value)
- X
- X This expression sets the value of a user variable.
- X
- X (COND [(test expr*)]*) execute conditionally
- X (IF test then-expr [else-expr]) traditional if-then-else
- X (WHILE test expr*) conditional iteration
- X (PROGN expr*) block construct
- X (RETURN [expr]) return from a function
- X
- X These statements are control constructs.
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X ADVSYS An Adventure Writing System Page 17
- X
- X
- X Primary expressions:
- X
- X integer (digits preceeded by an optional sign)
- X string (characters enclosed in double quotes)
- X action-name (an action name)
- X object-name (an object or class name)
- X property-name (a property name)
- X constant-name (a defined constant or function)
- X variable-name (a variable name)
- X
- X Since an adventure description contains a large quantity of
- X running text, the format for specifying string constants is
- X somewhat extended from normal programming languages. In
- X this system, a string is enclosed in double quotes. If the
- X end of line occurs before the closing quote within a string,
- X it is treated as if it were a space. Any number of
- X consecutive spaces is collapsed into a single space. Also,
- X the character pair "\\n" is used to represent the "end of
- X line" character, the pair "\\t" is used to represent the tab
- X character and the pair "\\\\" is used to represent the
- X backslash character.
- X
- X Examples:
- X
- X "This is a string.\\n"
- X "This
- X is
- X a
- X string.\\n"
- X
- X Both of the examples above represent the same string.
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X ADVSYS An Adventure Writing System Page 18
- X
- X
- X Definitions of symbols used above:
- X
- X expr an expression
- X value an expression
- X test an expression (NIL means false, anything
- Xelse is true)
- X then-expr an expression
- X else-expr an expression
- X obj an expression that evaluates to an object
- X property-name an expression that evaluates to a property
- Xname
- X noun-phrase-number an expression that evaluates to a noun
- Xphrase number
- X variable a variable name
- X T true
- X NIL false
- X
- X
- X Built-in variables set by the parser:
- X
- X $ACTOR (actor noun phrase number)
- X $ACTION (action)
- X $DOBJECT (first direct object noun phrase number)
- X $NDOBJECTS (number of direct object noun phrases)
- X $IOBJECT (indirect object noun phrase number)
- X
- X
- X Other built-in variables:
- X
- X $OCOUNT (total number of objects in the system)
- X
- X
- X CURRENT COMPILER LIMITS
- X
- X 500 words
- X 500 objects
- X 20 properties per object
- X 200 actions or functions
- X 16384 bytes of code
- X 16384 bytes of data
- X 262144 bytes of text
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- END_OF_advsys.doc
- if test 29358 -ne `wc -c <advsys.doc`; then
- echo shar: \"advsys.doc\" unpacked with wrong size!
- fi
- # end of overwriting check
- fi
- echo shar: End of archive 1 \(of 3\).
- cp /dev/null ark1isdone
- MISSING=""
- for I in 1 2 3 ; do
- if test ! -f ark${I}isdone ; then
- MISSING="${MISSING} ${I}"
- fi
- done
- if test "${MISSING}" = "" ; then
- echo You have unpacked all 3 archives.
- rm -f ark[1-9]isdone
- else
- echo You still need to unpack the following archives:
- echo " " ${MISSING}
- fi
- ## End of shell archive.
- exit 0
-
-
-
-